package com.snake.springboot.custom.service.assemble.goods;


import com.snake.springboot.custom.api.model.goods.StrategyGoodsModel;
import com.snake.springboot.custom.api.model.goods.StryGoodsDetailModel;
import com.snake.springboot.custom.api.response.goods.StrategyGoodsRsp;
import com.snake.springboot.custom.dao.mybatis.entity.goods.StrategyGoodsDO;
import org.snake.common.code.SerialNumberGeneratorFactory;
import org.snake.common.utils.ListUtils;
import org.snake.common.utils.PropertyUtils;

import java.util.List;

/**
 * <p>策略商品组装器
 * 类{@code StrategyGoodsAssembler} </br>
 * 创建时间2025/3/27 16:29
 *
 * @author yangxt
 * @see
 */
public class StrategyGoodsAssembler {
    public static StrategyGoodsDO toGoodsDO(StrategyGoodsModel model,boolean isAdd) {
        if (isAdd){
            model.setStrategyGoodsId(SerialNumberGeneratorFactory.buildId4Bean());
        }
        List<StryGoodsDetailModel> details = model.getDetailList();
        if (!ListUtils.isEmpty(details)){
            for (StryGoodsDetailModel detail : details) {
                detail.setStrategyGoodsId(model.getStrategyGoodsId());
                detail.setStryGoodsDetailId(SerialNumberGeneratorFactory.buildId4Bean());
            }
        }
        StrategyGoodsDO goodsDO = new StrategyGoodsDO();
        PropertyUtils.copyProperties(goodsDO,model);
        return goodsDO;
    }

    public static StrategyGoodsDO toGoodsDO(Object query) {
        StrategyGoodsDO goodsDO = new StrategyGoodsDO();
        PropertyUtils.copyProperties(goodsDO,query);
        return goodsDO;
    }

    public static StrategyGoodsRsp toGoodsRsp(StrategyGoodsDO goodsDO) {
        StrategyGoodsRsp rsp = new StrategyGoodsRsp();
        PropertyUtils.copyProperties(rsp,goodsDO);
        return rsp;
    }
}
